<template>
  <view class="cart-container">
  <!-- 收获地址组件 -->
    <my-address></my-address>
    <!-- 商品列表的标题区域 -->
    <view class="cart-title">
      <!-- 左侧的图标 -->
      <uni-icons type="shop" size="18"></uni-icons>
      <!-- 右侧的文字 -->
      <text class="cart-title-text">购物车</text>
    </view>
    <!-- 商品列表的数据 -->
    <uni-swipe-action>
      <block v-for="(goods,index) in cart" :key="index">
        <uni-swipe-action-item :right-options="options" @click="deleteItem(goods)">
          <my-goods :goods="goods" :show-radio="true" :show-num="true" @radio-change="changeRadio"></my-goods>
        </uni-swipe-action-item>
      </block>
    </uni-swipe-action>
<my-settle></my-settle>
  </view>
</template>

<script>
  import badgeMix from '../../mixin/tabbar-badge.js'
  import {
    mapState,
    mapMutations
  } from 'vuex'
  export default {
    mixins: [badgeMix],
    computed: {
      ...mapState('m_cart', ['cart'])
    },
    data() {
      return {
        options: [{
          text: '删除',
          style: {
            backgroundColor: '#C00000'
          }
        }]
      };
    },
    methods: {
      ...mapMutations('m_cart', ['updateGoodsState','removeGoodsItem']),
      changeRadio(e) {
        // console.log(e)
        this.updateGoodsState(e)
      },
      deleteItem(goods){
       this.removeGoodsItem(goods)
      }
    }
  }
</script>

<style lang="scss">
  .cart-container{
    padding-bottom: 50px;
  }
  .cart-title {
    height: 40px;
    display: flex;
    align-items: center;
    padding-left: 5px;
    border-bottom: 1px solid #efefef;

    .cart-title-text {
      font-size: 14px;
      margin-left: 10px;
    }
  }
</style>